<?php
/**
 * Created by PhpStorm.
 * User: papa
 * Date: 18/5/11
 * Time: 07:59
 */

namespace app\api\lib\exception;
use think\Exception;


/**
 * Class BaseException
 * 自定义异常类的基类
 */
class BaseException extends Exception
{
    public $code = 400; //  错误码
    public $msg = 'invalid parameters'; //错误信息
    public $status = 'ok';  //成功：ok，失败: fasle
    public $data = array(); //如果有数据集返回

    /**
     * 构造函数，接收一个关联数组
     * @param array $params 关联数组只应包含code、msg和status和data
     */
    public function __construct($params=[])
    {
        if(!is_array($params)){
            return;
        }
        if(array_key_exists('code',$params)){
            $this->code = $params['code'];
        }
        if(array_key_exists('msg',$params)){
            $this->msg = $params['msg'];
        }
        if(array_key_exists('status',$params)){
            $this->status = $params['status'];
        }
        if(array_key_exists('data',$params)){
            $this->data = $params['data'];
        }
    }
}